export default class test extends Laya.Script {
    /** @prop {name:btn_load, tips:"按键位置", type:Node, default:1000}*/
    public btn_load:Laya.Node = null;

    /** @prop {name:btn_save, tips:"按键位置", type:Node, default:1000}*/
    public btn_save:Laya.Node = null;

     /** @prop {name:btn_event, tips:"按键位置", type:Node, default:1000}*/
     public btn_event:Laya.Node = null;

    /** @prop {name:btn_utils, tips:"按键位置", type:Node, default:1000}*/
    public btn_utils:Laya.Node = null;

     /** @prop {name:btn_alert, tips:"按键位置", type:Node, default:1000}*/
     public btn_alert:Laya.Node = null;

      /** @prop {name:btn_win, tips:"按键位置", type:Node, default:1000}*/
    public btn_win:Laya.Node = null;
     
      /** @prop {name:btn_http, tips:"按键位置", type:Node, default:1000}*/
    public btn_http:Laya.Node = null;

      /** @prop {name:btn_music, tips:"按键位置", type:Node, default:1000}*/
      public btn_music:Laya.Node = null;
     
      /** @prop {name:btn_effect, tips:"按键位置", type:Node, default:1000}*/
    public btn_effect:Laya.Node = null;

     /** @prop {name:btn_res, tips:"预加载", type:Node, default:1000}*/
     public btn_res:Laya.Node = null;

     /** @prop {name:btn_res_test, tips:"预加载测试", type:Node, default:1000}*/
     public btn_res_test:Laya.Node = null;
    
    music_flag:boolean = true;
    constructor() { super(); }

    onStart(){
        let progressBar:Laya.ProgressBar = this.owner.getChildByName('process_bar') as Laya.ProgressBar;       
       
        progressBar.value = 0.3;//当前的进度量.介于0和1之间,默认不设置时是0.5，即会出现在中间的位置
    }
    
    onEnable(): void {
        console.log('test onEnable');
        console.log('orc:',orc.orc_config.DEBUG);
        orc.log("orc.log",orc.orc_config.DEBUG);
        this.btn_load.on(Laya.Event.CLICK,this,this.btn_load_click); 
        
        this.btn_load.on(Laya.Event.CLICK,this,this.btn_load_click);    //测试读取本地数据按钮
        this.btn_save.on(Laya.Event.CLICK,this,this.btn_save_click);    //测试存取本地数据按钮

        this.btn_event.on(Laya.Event.CLICK,this,this.btn_event_click);    //测试事件按钮
        orc.event_manager.add_listener("event_test",this.event_test.bind(this));

        this.btn_utils.on(Laya.Event.CLICK,this,this.btn_utils_click);    //测试工具按钮

        this.btn_http.on(Laya.Event.CLICK,this,this.btn_http_click);    //测试网络按钮

        this.btn_music.on(Laya.Event.CLICK,this,this.btn_music_click);    //测试音乐按钮

        this.btn_effect.on(Laya.Event.CLICK,this,this.btn_effect_click);    //测试音效按钮

        this.btn_alert.on(Laya.Event.CLICK,this,this.btn_alert_click);    //测试提示按钮

        this.btn_win.on(Laya.Event.CLICK,this,this.btn_win_click);    //测试窗口按钮

        this.btn_res.on(Laya.Event.CLICK,this,this.btn_res_click);    //预加载按钮,加载提示和窗口

        this.btn_res_test.on(Laya.Event.CLICK,this,this.btn_res_test_click);    //测试预加载按钮
    }

    btn_load_click(){
        orc.orc_data.load_local_data();
    }
    
    btn_res_click(){
        orc.res_manager.res_pkg = {};
        orc.res_manager.res_pkg["prefabs"] = [
            "prefabs/common/alert_tip.json",
            "prefabs/common/loading_tip.json",
            "prefabs/win/win_over.json"
        ];       
        orc.res_manager.preload_res_pkg();
    }

    btn_res_test_click(){
        orc.log(orc.res_manager.prefabs_res);
    }

    btn_save_click(){
        orc.orc_data.local_data.money = 5;
        orc.orc_data.save_local_data();
    }

    btn_event_click(){
        orc.event_manager.dispatch_event("event_test");
    }

    event_test(){
        orc.log("event test ok");
    }

    btn_utils_click(){
        let a =orc.orc_utils.get_random(1,6);
        orc.log('asd',a);        
    }

    btn_alert_click(){
        orc.log('提示');
        orc.prefab_manager.show_alert_tips("alert提示");        
    }
    
    btn_win_click(){
        orc.log('窗口');
        //orc.prefab_manager.show_loading_tip(); 
        orc.prefab_manager.win_open('win_over');
    }

    btn_http_click(){
        orc.log("http test");
        
        let body = [];
        body["platform_id"] = "0";
        body["game_tag"] = orc.orc_config.GAME_NAME;
        body["time"] =Math.floor(new Date().getTime()/1000);
        orc.orc_net.http_post(orc.orc_url_config.game_config,body).then((result:any)=>{
            orc.log("http result:",result);
            orc.log("http result:",result.code);
        });
        
    }

    btn_music_click(){
        if(this.music_flag)
        {
            this.music_flag = false;
            orc.sound_manager.play_music("bgm.mp3");
        }
        else
        {
            this.music_flag = true;
            orc.sound_manager.stop_music();
        }
        
    }

    btn_effect_click(){
        orc.sound_manager.play_effect("Win.mp3");

        // Laya.Scene.open
    }

    onDisable(): void {

    }
    
}